using System;
using Microsoft.SPOT;
using dotnetwarrior.NetMF.DL40;

namespace DLIOTest
{
    class TestCapture
    {
        static DLIOModule Module;
        static IPulseCounterPin Counter;
        
        public static void Run(DLIOModule module, Gadgeteer.Interfaces.PWMOutput pwm)
        {
            Module = module;

            // Create a Capture Pin using Timer 0, which is a 16 bit timer capturing pin 0.2
            Counter = module.CreateCapturePin(CapturePinId.Capture16_0_2,
              Microsoft.SPOT.Hardware.Port.ResistorMode.PullDown,
              Microsoft.SPOT.Hardware.Port.InterruptMode.InterruptEdgeHigh, true);

            pwm.Set(2000, 0.8);

            Gadgeteer.Timer timer = new Gadgeteer.Timer(1000);
            timer.Tick += new Gadgeteer.Timer.TickEventHandler(timer_Tick);
            timer.Start();
        }

        static void timer_Tick(Gadgeteer.Timer timer)
        {
            // Read the counter value
            ulong reading = Counter.ReadCounter();

            Debug.Print("Last Count : " + reading);
        }

    }
}
